{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-collapse ns-tips">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">操作提示</h2>
		<ul class="layui-colla-content layui-show">
			<li>当前页面对商城的信息进行管理，可以添加商城，查看商城账户信息，认证信息等。</li>
		</ul>
	</div>
</div>

<!-- 列表 -->
<table id="shop_list" lay-filter="shop_list"></table>

<!-- 工具栏操作 -->
<script type="text/html" id="operation">
	<div class="ns-table-btn">
		<a class="layui-btn" lay-event="detail">店铺详情</a>
	</div>
</script>
{/block}

{block name="script"}
<script>
	layui.use(['form', 'laydate', 'laytpl'], function() {
		var table,
			form = layui.form,
			laytpl = layui.laytpl;
			laydate = layui.laydate;
		form.render();

		table = new Table({
			elem: '#shop_list',
			url: ns.url("admin/sysuser/shoplists"),
			where:{
			   sys_uid:{$sys_uid}
			},
			cols: [
				[{
					field: 'site_name',
					title: '商城名称',
					width: '20%',
					unresize: 'false'
				}, {
					field: 'username',
					title: '商家账号',
					width: '20%',
					unresize: 'false'
				}, {
					field: 'group_name',
					title: '开店套餐',
					width: '20%',
					unresize: 'false'
				}, {
					field: 'create_time',
					title: '开店时间',
					width: '20%',
					unresize: 'false',
					templet: function(data) {
						return ns.time_to_date(data.create_time);
					}
				}, {
					title: '操作',
					width: '20%',
					toolbar: '#operation',
					unresize: 'false'
				}]
			]
		});
		
		/**
		 * 搜索功能
		 */
		form.on('submit(search)', function(data) {
			table.reload({
				page: {
					curr: 1
				},
				where: data.field
			});
			return false;
		});

        //批量导出
        form.on('submit(export)', function(data){
            data.field.order_type = 1;
            location.href = ns.url("admin/shop/exportShop",data.field);
            return false;
        });

		/**
		 * 监听工具栏操作
		 */
		table.tool(function(obj) {
			var data = obj.data,
					event = obj.event;
			switch (event) {
				case 'detail': //基本信息
					location.href = ns.url("admin/shop/shopDetail" + "?site_id=" + data.site_id);
					break;
				case 'change_domain'://修改域名
					changeDomain(data);
					break;
				case 'edit':
					location.href = ns.url("admin/shop/edit" + "?site_id=" + data.site_id);
			}
		});

		/**
		 * 重置密码
		 */
		function changeDomain (data) {
			laytpl($("#change_domain").html()).render(data, function(html) {
				layer_domian = layer.open({
					title: '重置域名',
					skin: 'layer-tips-class',
					type: 1,
					area: ['600px'],
					content: html,
				});
			});
		}

		form.on('submit(domian)', function(data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			$.ajax({
				type: "POST",
				dataType: 'JSON',
				url: ns.url("admin/shop/changeDomain"),
				data: data.field,
				success: function(res) {
					repeat_flag = false;

					if (res.code == 0) {
						layer.msg('操作成功');
						location.reload();
					} else {
						layer.msg(data.message)
					}
				}
			});
		});
	});
</script>
{/block}